#!/usr/bin/python
# MyMuNetConfigExample.py
import MuConnection, MuNetworkConfiguration, time, sys, getopt

USERNAME = 'admin'
PASSWORD = ''
MU = ''

#get the username and password
args = sys.argv[0:]
try:
    options, remainder = getopt.getopt(sys.argv[1:], "u:p:i:", ["username=", "password=","ipaddress="])
except getopt.GetoptError, err:
    # print help information and exit:
    print str(err) # will print something like "option -a not recognized"
    usage()
    sys.exit(2)
for o, p in options:
    if o in ("-u","--username"):
     	USERNAME = p
    elif o in ("-p", "--password"):
     	PASSWORD = p
    elif o in ("-i", "--ipaddress"):
        MU = p

myMuConnection = MuConnection.MuConnection(MU,USERNAME,PASSWORD)



myConfig = MuNetworkConfiguration.MuNetworkConfig(myMuConnection)
myConfig.VERBOSE = True
myMuConnection.VERBOSE - True
myConfig.downloadNetworkConfigObject()

if True:
	# new empty host
	myHost = MuNetworkConfiguration.host()
	myHost.setName("ABC-SERVER")
	myHost.setV4_addr("192.168.121.121")
	
	# is the host on Mu
	response = myConfig.isHostPresent(myHost.getName())
	print response
	time.sleep(1)
	# add the host to Mu
	myConfig.addHost(myHost)
	time.sleep(1)
	# is the host on Mu
	response = myConfig.isHostPresent(myHost.getName())
	print response
	time.sleep(1)
	myHost.setNotes("test note")
	myHost.setV4_addr("192.168.111.222")
	#modify host on Mu
	print "Modify te host"
	myConfig.modifyHost(myHost)
	time.sleep(60)
	# delete Host on Mu
	myConfig.deleteHost(myHost)
	time.sleep(1)

if True:
	myRoute = MuNetworkConfiguration.route()
	myRoute.setDst("192.168.200.0")
	myRoute.setDst_pfx_len(30)
	myRoute.setGateway("192.168.100.121")
	myRoute.setInterface("A1")
	response = myConfig.isRoutePresent(myRoute.getDst())
	print response
	time.sleep(1)
	myConfig.addRoute(myRoute)
	myRoute.setGateway("192.168.100.122")
	myRoute.setDst_pfx_len(29)
	time.sleep(1)
	myConfig.modifyRoute(myRoute)
	time.sleep(1)
	response = myConfig.isRoutePresent(myRoute.getDst())
	print response
	myConfig.deleteRoute(myRoute)
		
if True:
	myInterface = MuNetworkConfiguration.interface()
	myInterface.setName('a1.2001')
	myInterface.setV4_addrs(['192.168.111.5','192.168.111.6','192.168.111.7','192.168.111.8'])
	myInterface.setVlan(2001)
	myInterface.setV4_mask(24)
	print myInterface
	response = myConfig.isInterfacePresent('a1')
	print response
	time.sleep(1)
	response = myConfig.isInterfacePresent(myInterface.getName())
	print response
	time.sleep(1)
	myConfig.addInterface(myInterface)
	time.sleep(1)
	response = myConfig.isInterfacePresent(myInterface.getName())
	print response
	myInterface.setV4_addrs(['192.168.112.5','192.168.112.6','192.168.112.7','192.168.112.8'])
	time.sleep(1)
	response = myConfig.isInterfacePresent(myInterface.getName())
	print response
	time.sleep(1)
	myConfig.modifyInterface(myInterface)
	time.sleep(1)
	response = myConfig.isInterfacePresent(myInterface.getName())
	print response
	myInterface2 = MuNetworkConfiguration.interface()
	myInterface2.setName('a1.2001.4000')
	myInterface2.setV4_addrs(['192.168.123.5','192.168.123.6','192.168.123.7','192.168.123.8'])
	myInterface2.setVlan(4444)
	myInterface2.setV4_mask(24)
	myConfig.addInterface(myInterface2)
	myInterface.setName('a1.2001')
	# delete will fail. Need to remove child vlan first
	myConfig.deleteInterface(myInterface)
	myInterface2.setName('a1.2001.4000')
	myConfig.deleteInterface(myInterface)
	myInterface.setName('a1.2001')
	myConfig.deleteInterface(myInterface)
	
if True:	
	myInterface = myConfig.getInterface("a1")
	print myInterface
	myHost = myConfig.getHost('VoIP100')
	print myHost
	myRoute = myConfig.getRoute('192.168.100.0')
	print myRoute
	
	
